import BuildArea from './common/modules/BuildArea/index.js';
import BuildItem from './common/modules/BuildItem/index.js';
import RenderGroup from './common/utils/RenderGroup.js';
class Hook {
	constructor(modules) {
		if (Hook.instance) {
			return Hook.instance
		} else {
			this.$m = modules;
			Hook.instance = this;
		}
	}
	initJiess(instance) {
		if (!this.jiess) this.jiess = this.$m.$jiess();
		instance.jiess = this.jiess;
		return instance;
	}
	buildArea(...args) {
		const buildArea = new BuildArea(this, ...args);
		return this.initJiess(buildArea).init();
	}
	buildItem(...args) {
		return (...info) => this.initJiess(
			new BuildItem(this, ...args).init(...info)
		);
	}
	initValue({ param, info }) {
		let { defaultValue = null, ...other } = param;
		// 例如下拉多选时，默认值需要指定为 []
		if (typeof defaultValue === 'function') {
			other.defaultValue = defaultValue(info);
		}
		return other;
	}
	initGroup(...args) {
		return new RenderGroup(...args);
	}
	// 这里的key实际为name或prop
	initFormItem(field, key, ...args) {
		const result = {};
		if (key) {
			const obj = { key };
			obj[field] = key;
			Object.assign(result, obj);
		}
		return Object.assign(result, ...args);
	}
	// ----------------------------
	hookRadioButton(param) {
		// vue中无需处理
	}
	hookNameManger(buildItem) {
		// react无需处理
	}
	hookNameMangerInput(values, field, val) {
		// vue2中需强响应式赋值
		values[field] = val;
	}
}
export default Hook;